// 发请求的函数引入过来
import { reqGoodDetailInfoData } from '@/api/cart'
const state = {
  goodDetailInfo: {}
}
const actions = {
  async getGoodDetailInfo({commit},id) {
    const result = await reqGoodDetailInfoData(id)
    if (result.code === 200) {
    // console.log(result)
      commit('SAVE_GOOD_DETAIL_INFO',result.data)
    } else {
      console.log(result.message);
    }
  }
}
const mutations = {
  SAVE_GOOD_DETAIL_INFO(state,payload) {
    state.goodDetailInfo = payload
  }
}
const getters = {
  categoryView(state) {
    return state.goodDetailInfo.categoryView || {}
  },
  skuInfo(state) {
    return state.goodDetailInfo.skuInfo || {}
  },
  spuSaleAttrList(state) {
    return state.goodDetailInfo.spuSaleAttrList || {}
  },
  skuImageList(state){
    return (state.goodDetailInfo.skuInfo || {}).skuImageList || []
  },
  skuSaleAttrValueList(){
    return (state.goodDetailInfo.skuInfo || {}).skuSaleAttrValueList || []
  }
}

export default {
  namespaced: true,
  state,
  actions,
  mutations,
  getters
}